package br.com.monitor.testesDeUnidade;

import br.com.monitor.modelos.CalculaIndices;
import br.com.monitor.modelos.InformacoesFisicas;
import br.com.monitor.modelos.Usuario;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class TesteCalculadora {

	InformacoesFisicas magro, mediano, ideal, gordo, obeso;
	Usuario user1, user2, user3, user4, user5;

	@Before
	public void criaInformacoes() {
		try {
			InformacoesFisicas magro = new InformacoesFisicas(65.0, 170.0, 0.5,
					1.3, 1.6, 0.9);
			InformacoesFisicas ideal = new InformacoesFisicas(56.0, 160.0, 0.6,
					1.6, 1.8, 8.4);
			InformacoesFisicas mediano = new InformacoesFisicas(65.0, 170.0,
					1.0, 1.8, 2.0, 9.2);
			InformacoesFisicas gordo = new InformacoesFisicas(80.0, 166.0, 1.8,
					2.3, 2.1, 10.0);
			InformacoesFisicas obeso = new InformacoesFisicas(95.0, 172.0, 2.3,
					2.6, 2.8, 10.8);
			user1 = new Usuario("ProfLivia", 20, "feminino", "login123",
					"senha123", magro);
			user2 = new Usuario("ProfLivia", 20, "feminino", "login123",
					"senha123", ideal);
			user3 = new Usuario("ProfLivia", 20, "feminino", "login123",
					"senha123", mediano);
			user4 = new Usuario("ProfLivia", 20, "feminino", "login123",
					"senha123", gordo);
			user5 = new Usuario("ProfLivia", 20, "feminino", "login123",
					"senha123", obeso);

		} catch (Exception e) {
			Assert.fail();
		}
	}
	
	@Test
	public void testaExcecoes() {

		try {
			CalculaIndices.calculaIMC(null);
			Assert.fail();
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}

		try {
			CalculaIndices.porcentagemGorduraComAdipometro(null);
			Assert.fail();
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}

		try {
			CalculaIndices.calculaPesoMagro(null);
			Assert.fail();
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}

		try {
			CalculaIndices.calculaPesoGordo(null);
			Assert.fail();

		} catch (Exception e) {
			System.out.println(e.getMessage());
		}

	}



	@Test
	public void testaPorcentualGordura() {

		Assert.assertEquals(11,
				CalculaIndices.porcentagemGorduraComAdipometro(user1), 0);
		Assert.assertEquals(13,
				CalculaIndices.porcentagemGorduraComAdipometro(user2), 0);
		Assert.assertEquals(15,
				CalculaIndices.porcentagemGorduraComAdipometro(user3), 0);
		Assert.assertEquals(19,
				CalculaIndices.porcentagemGorduraComAdipometro(user4), 0);
		Assert.assertEquals(23,
				CalculaIndices.porcentagemGorduraComAdipometro(user5), 0);

	}

	@Test
	public void testaIMC() {

		Assert.assertEquals(22, CalculaIndices.calculaIMC(user1), 0);
		Assert.assertEquals(22, CalculaIndices.calculaIMC(user2), 0);
		Assert.assertEquals(22, CalculaIndices.calculaIMC(user3), 0);
		Assert.assertEquals(29, CalculaIndices.calculaIMC(user4), 0);
		Assert.assertEquals(32, CalculaIndices.calculaIMC(user5), 0);

	}

	@Test
	public void testaPesoGordo() {

		Assert.assertEquals(7.0, CalculaIndices.calculaPesoGordo(user1), 0);
		Assert.assertEquals(7.0, CalculaIndices.calculaPesoGordo(user2), 0);
		Assert.assertEquals(10.0, CalculaIndices.calculaPesoGordo(user3), 0);
		Assert.assertEquals(15.0, CalculaIndices.calculaPesoGordo(user4), 0);
		Assert.assertEquals(22.0, CalculaIndices.calculaPesoGordo(user5), 0);

	}

	@Test
	public void testaPesoMagro() {

		Assert.assertEquals(58.0, CalculaIndices.calculaPesoMagro(user1), 0);
		Assert.assertEquals(49.0, CalculaIndices.calculaPesoMagro(user2), 0);
		Assert.assertEquals(55.0, CalculaIndices.calculaPesoMagro(user3), 0);
		Assert.assertEquals(65.0, CalculaIndices.calculaPesoMagro(user4), 0);
		Assert.assertEquals(73.0, CalculaIndices.calculaPesoMagro(user5), 0);

	}

}
